﻿// // ******************************************************************
// //       /\ /|       @file       ConfigService.cs
// //       \ V/        @brief      await29
// //       | "")       @author     Await, 285283010@qq.com
// //       /  |
// //      /  \\        @Modified   2024-12-31 20:12
// //    *(__\_\        @Copyright  Copyright (c) , 2024-12-25 18:12 Await
// // ******************************************************************

using AutomaticSubtitles.Contracts.Dto;
using AutomaticSubtitles.Contracts.Vo;
using AutomaticSubtitles.Service.Application.Config.Commands;
using AutomaticSubtitles.Service.Application.Config.Queries;

namespace AutomaticSubtitles.Service.Services;

[Tags("配置")]
public class ConfigService : BaseService<ConfigService>
{
    [EndpointDescription("获取配置")]
    [EndpointName("获取配置")]
    [EndpointSummary("获取配置")]
    [Authorize]
    public async Task<ResponseModel<IReadOnlyList<ConfigDto>>> GetList()
    {
        var query = new GetListConfigQuery();
        await PublishAsync(query);
        return query.Result.CreateResult();
    }

    [EndpointDescription("添加配置")]
    [EndpointName("添加配置")]
    [EndpointSummary("添加配置")]
    [Authorize]
    public async Task<ResponseModel<int>> AddAsync(ConfigVo data)
    {
        var query = new CreateConfigAddCommand(data);
        await PublishAsync(query);
        return query.Result.CreateResultAdd_Msg();
    }

    [EndpointDescription("更新配置")]
    [EndpointName("更新配置")]
    [EndpointSummary("更新配置")]
    [Authorize]
    public async Task<ResponseModel<int>> UpdateAsync(ConfigVo data)
    {
        var query = new UpdateConfigAddCommand(data);
        await PublishAsync(query);
        return query.Result.CreateResultUpdate_Msg();
    }

    [EndpointDescription("删除配置")]
    [EndpointName("删除配置")]
    [EndpointSummary("删除配置")]
    [Authorize]
    public async Task<ResponseModel<int>> DeleteAsync(string id)
    {
        var query = new DeleteConfigAddCommand(id);
        await PublishAsync(query);
        return query.Result.CreateResultDelete_Msg();
    }

    [EndpointDescription("获取配置类型")]
    [EndpointName("获取配置类型")]
    [EndpointSummary("获取配置类型")]
    [Authorize]
    public async Task<ResponseModel<List<BasicsSelectDto<int>>>> GetTypeAsync()
    {
        var data = (from object? day in Enum.GetValues(typeof(GlobalVariableEnumConfiguration.ConfigurationTypeEnum))
            select new BasicsSelectDto<int>() { Value = (int)day, Label = $"{day}" }).ToList();
        return data.CreateResult();
    }

    [EndpointDescription("获取指定类型数据")]
    [EndpointName("获取指定类型数据")]
    [EndpointSummary("获取指定类型数据")]
    [Authorize]
    public async Task<ResponseModel<IReadOnlyList<BasicsSelectDto<string>>>> GetTypeList(int type)
    {
        var query = new GetConfigTypeListData(type);
        await PublishAsync(query);
        return query.Result.CreateResult();
    }
}